package cn.dnui_cjy529.dnuifood_16110100529.Adapter;


import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.dnui_cjy529.dnuifood_16110100529.bean.CollectStatus;
import cn.dnui_cjy529.dnuifood_16110100529.R;
import cn.dnui_cjy529.dnuifood_16110100529.model.UserModel;

public  class FoodAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List<CollectStatus> foodInfo;
    private LayoutInflater mLayoutInflater;
//    private ImageButton collect_1;
//    private TextView foodname,intro,price;
//    private ImageView pic;
    //private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    public FoodAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.foodInfo = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.collect_adapter,parent,false);
        // v.setOnClickListener((View.OnClickListener) this);
        return new  ViewHolder(v);
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final CollectStatus entity = (CollectStatus) foodInfo.get(position);
        if (null == entity)
            return;
        FoodAdapter.ViewHolder viewHolder = (FoodAdapter.ViewHolder) holder;
        viewHolder.collect_name.setText(entity.getShopname());
        viewHolder.collect_content.setText(entity.getAddress());
//        viewHolder.collect_foodid.setText(entity.getShop_id());

        Picasso.with(mContext).load(UserModel.Constants.BASE_URL+entity.getPic()).into(viewHolder.collect_pic);


    }


    @Override
    public int getItemCount() {
        if (foodInfo==null)
            return 0;
        else
            return foodInfo.size();
    }


    private class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView collect_pic;
        private TextView collect_name,collect_content,collect_shopid,collect_foodid;
        private Button collect_enter, collect_cancle;
        public ViewHolder(View itemView) {
            super(itemView);
            collect_pic=(ImageView)itemView.findViewById(R.id.collectfragment_pic);
            collect_name=(TextView) itemView.findViewById(R.id.collectfragment_name);
            collect_content=(TextView) itemView.findViewById(R.id.collectfragment_content);
            collect_foodid=(TextView) itemView.findViewById(R.id.collectfragment_foodid);
            collect_shopid=(TextView)itemView.findViewById(R.id.collectfragment_shopid);
            collect_enter=(Button) itemView.findViewById(R.id.collect_enter);
            collect_cancle=(Button) itemView.findViewById(R.id.collect_cancle);
        }
    }

}
